<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<%@ include file="../base/top_css.jsp"%>
</head>

<body>
<%@ include file="../base/top.jsp"%>
<%@ include file="../base/left.jsp"%>
<div class="mainbar">

	<!-- Page heading -->
	<div class="page-head">
		<h2 class="pull-left">
			<i class="icon-home"></i> 首页
		</h2>

		<!-- Breadcrumb -->
		<div class="bread-crumb pull-right">
			<a href="${pageContext.request.contextPath }/base/index.jsp"><i class="icon-home"></i> 首页</a>
			<!-- Divider -->
			<span class="divider">/</span> <a href="#" class="bread-current">控制台</a>
		</div>
		
		<div class="clearfix" ></div>

		</div>

	<div class="matter">
		<div class="container" id="con">
		<!-- action="${pageContext.request.contextPath }/goods/findsupplier.action " 
		href="${pageContext.request.contextPath }/jsps/supplier_add.jsp">新建 
		-->
		<div class="padd">

                    <h6>供应商管理</h6>
                    <hr>
                    <!-- Form starts.  -->
                     <form class="form-horizontal" role="form" id="cha" action="${pageContext.request.contextPath }/goods/findsupplier.action" method="post">
                              
                                <div class="form-group">
                                  <label class="col-lg-4 control-label">供应商</label>
                                  <div class="col-lg-8">
                                    <input type="text" class="form-control" placeholder="供应商 "  name="name"  id="name" >
                                  </div>
                                </div>
                                <div class="form-group">
                                  <label class="col-lg-4 control-label">联系人</label>
                                  <div class="col-lg-8">
                                    <input type="text" class="form-control" placeholder="联系人"  name="contact" id="contact" >
                                  </div>
                                </div>
                                <div class="form-group">
                                  <label class="col-lg-4 control-label">联系电话</label>
                                  <div class="col-lg-8">
                                    <input type="text" class="form-control" placeholder="联系电话" name="tele" id="tele">
                                  </div>
                                </div>

                                <div class="form-group">
                                  <label class="col-lg-4 control-label">送货方式</label>
                                  <div class="col-lg-8">
                                    <select class="form-control"  name="needs" id="needs">
                                      <option value="0">-请选择-</option>
                                      <option value="1">送货</option>
                                      <option value="2">提货</option>    
                                    </select>
                                  </div>
                                </div>     
                                <hr>
                                <div class="form-group">
                                  <div class="col-lg-offset-1 col-lg-9">
                                    <button type="button" class="btn btn-primary"  onclick="new1()" >新建</button>
                                    <button type="button" class="btn btn-warning"  onclick="cha()">模糊查找</button>
                                  </div>
                                </div>
                              </form>
                 	   </div>
		
			<div class="col-md-6" style="width : 1100px">
                <div class="widget">
                <div class="widget-head">
                  <div class="pull-left">Tables</div>
                  <div class="widget-icons pull-right">
                    <a href="#" class="wminimize"><i class="icon-chevron-up"></i></a> 
                    <a href="#" class="wclose"><i class="icon-remove"></i></a>
                  </div>  
                  <div class="clearfix"></div>
                </div>

                  <div class="widget-content">

                    <table class="table table-striped table-bordered table-hover" >
                      <thead>
                        <tr>
                        <td width="20%" height="30">供应商</td>
						<td width="20%">地址</td>
						<td width="20%">联系人</td>
						<td width="12%">电话</td>
						<td width="12%">送货方式</td>
						<td width="16%">操作</td>
                        </tr>
                      </thead>
                      <tbody id="trs">
                   	  </tbody>
                    </table>
						<!--分页 -->
                   <div class="widget-foot">
                        <ul class="pagination pull-right">
                          <li><a href="#">Prev</a></li>
                          <li><a href="#">1</a></li>
                          <li><a href="#">2</a></li>
                          <li><a href="#">3</a></li>
                          <li><a href="#">4</a></li>
                          <li><a href="#">Next</a></li>
                        </ul>
                      <div class="clearfix"></div>
                    </div>
                  </div>

                </div>
              </div>
	

          </div> 
		</div>
	</div>




</body>
<%@ include file="../base/top_js.jsp"%>
<script type="text/javascript">
$(function(){
	$.post("${pageContext.request.contextPath}/goods/supplier_list.action",
			{},
			function(result, start, resp) {
			//	alert(resp.responseText);
				var tr="";
				for (var i = 0; i < result.length; i++) {
					tr += '<tr><td>'+result[i].name+'</td><td>'+result[i].address+'</td><td>'+result[i].contact+'</td><td>'+result[i].tele+'</td><td><span class="label label-success">'+result[i].needsView+'</span></td><td><button class="btn btn-xs btn-default"  onclick="Edit('+result[i].uuid+')"><i class="icon-pencil"></i></button><button class="btn btn-xs btn-danger"  onclick="Del('+result[i].uuid+')" ><i class="icon-remove"></i> </button> </td></tr>';
				}
				$("#trs").append(tr);
	});
});

function cha(){
	$("#trs").empty();
	var name1 = $("#name").val().trim();	
	var contact1 =  $("input[name='contact']").val();
	var tele1 =  $("input[name='tele']").val();
	var needs1 =  $("select[name='needs']").val();
	//alert("供货商"+name1);
	//alert("联系人"+con);
	//alert("联系人电话"+tele1);
	//alert("供货方式"+needs);
	$.post("${pageContext.request.contextPath}/goods/findsupplier.action",
			{name: name1,contact:contact1,tele:tele1,needs:needs1},
			function(result, start, resp) {
			//alert(resp.responseText);
				var tr1="";
				for (var i = 0; i < result.length; i++) {
					tr += '<tr><td>'+result[i].name+'</td><td>'+result[i].address+'</td><td>'+result[i].contact+'</td><td>'+result[i].tele+'</td><td><span class="label label-success">'+result[i].needsView+'</span></td><td><button class="btn btn-xs btn-default"  onclick="Edit('+result[i].uuid+')"><i class="icon-pencil"></i></button><button class="btn btn-xs btn-danger"  onclick="Del('+result[i].uuid+')" ><i class="icon-remove"></i> </button> </td></tr>';
				}
			//	alert(tr1);
				
				$("#trs").append(tr1);
	});
	
}


function Edit(value){
	alert(value);
	location.href="${pageContext.request.contextPath}/goods/findsupplierById.action?id="+value;
}
function Del(value){
	alert(value);
	location.href="${pageContext.request.contextPath}/goods/delsupplierById.action?id="+value;
	alert("删除成功,请刷新页面");
}

function new1(){
	location.href="${pageContext.request.contextPath}/jsps/supplier_add.jsp";
}
</script>
</html>